import * as path from "path";
import React from "react";
import ReactDOMServer from 'react-dom/server'
import ServerApp from "../../src/serverApp";

const Router = require('koa-router');
const fs = require('fs');

const router = new Router();


export default (server) => {

  router.get('/others', (ctx) => {
    ctx.response.body = 123456
  });

  // 获取navBar图片List
  router.get('/(.*)', (ctx) => {
    const {req} = ctx
    const content = ReactDOMServer.renderToString(<ServerApp url={req.url}/>);
    const htmlString = fs.readFileSync(path.join(__dirname,'../src/index.html'),'utf-8')
    ctx.response.body = htmlString.replace('<!-- app -->', content)
  });


  server.use(router.routes());
};
